package com.corner.system.service.impl;

import com.corner.system.domain.vo.transferQueryVo;
import com.corner.system.domain.vo.transferRepVo;
import com.corner.system.mapper.TransferBatchesMapper;
import com.corner.system.service.TransferBatchesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: corner-admin
 * @description: 转账记录服务
 * @author: lydms
 * @create: 2024-06-11 11:15
 **/
@Service
public class TransferBatchesServiceImpl implements TransferBatchesService {

    @Autowired
    private TransferBatchesMapper transferBatchesMapper;
    @Override
    public List<transferRepVo> selectTransferBatches(transferQueryVo query) throws Exception {
        List<transferRepVo> transferRep = transferBatchesMapper.selectTransferBatches(query);
        return transferRep;
    }

    @Override
    public Map<String, Integer> selectTransferBatchesStatistics(transferQueryVo query) {
        query.setDetailStatus("SUCCESS");
        Map<String, Integer> SUM_SUCESS = transferBatchesMapper.selectTransferBatchesStatistics(query);
        Integer sumAmount_success = SUM_SUCESS.get("sumAmount");
        Integer sumCount_success = SUM_SUCESS.get("sumCount");
        query.setDetailStatus("FAIL");
        Map<String, Integer> SUM_FAIL = transferBatchesMapper.selectTransferBatchesStatistics(query);
        Integer sumAmount_fail = SUM_FAIL.get("sumAmount");
        Integer sumCount_fail = SUM_FAIL.get("sumCount");

        Map statistics = new HashMap<>();
        statistics.put("successSumAmount",sumAmount_success);
        statistics.put("successSumCount",sumCount_success);
        statistics.put("failSumAmount",sumAmount_fail);
        statistics.put("failSumCount",sumCount_fail);
        return statistics;
    }
}
